<template>
  <div>
    <el-dialog width="25%" :visible.sync="dialogFormVisible" @close="aa">
      <template slot="title">
        <div class="dialog-title">修改目录</div>
      </template>
      <el-form :model="formarr">
        <el-form-item label="所属学科">
          <el-select v-model="formarr.subjectName" @change="handleChange" placeholder="请选择">
            <el-option v-for="obj in arr" :key="obj.id" :label="obj.subjectName" :value="obj.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="目录名称">
          <el-input v-model="formarr.directoryName" autocomplete="off" placeholder="请输入目录名称"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="del">取 消</el-button>

        <el-button type="primary" @click="submit()">确 认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { lenlist, editfn } from '../../api/base/directorys'

export default {
  name: '',
  props: {
    form: {
      type: Object,
      required: true
    },
    dialogFormVisible: {
      type: Boolean,
      required: true
    }
  },
  components: {},
  data () {
    return {
      arr: [],
      id: 0,
      formarr: {}
    }
  },
  computed: {},
  watch: {
    form: function (newVal, oldVal) {
      this.formarr = Object.assign({}, newVal)
    }
  },
  created () {
    this.lenlist()
  },
  mounted () {},
  methods: {
    async lenlist () {
      // this.formarr = this.form
      console.log(this.formarr)
      // console.log(a)
      const { data } = await lenlist()
      // console.log(this.data)
      this.arr = data.items
      // console.log(this.arr)
    },
    handleChange (val) {
      // console.log(val)
      this.id = val
      // this.form.departmentId = val[val.length - 1]
    },
    aa () {
      this.$emit('bb')
    },
    del () {
      this.$emit('bb')
    },
    async  submit () {
      await editfn({
        id: this.formarr.id,
        subjectID: this.id,
        directoryName: this.formarr.directoryName

      })
      this.$message.success('修改成功')
      this.$emit('bb')
    }

  }

}
</script>

<style lang="scss" scoped>
.el-form-item {
  display: flex;
}
.el-select,
.el-input {
  width: 290px;
}
.button {
  width: 10px;
}
.dialog-title {
  color: #fff;
  text-align: left;
}
</style>
